package com.bao.work.work05;

/**
 * @author baoye
 * @date 2024-07-29/19:22
 */
public class StudentsTool {
    public void listStudents(Student[] arr) {
        System.out.print("姓名:\t");
        System.out.print("年龄:\t");
        System.out.println("分数:\t");
        for (Student student : arr) {
            System.out.print(student.getName()+"\t");
            System.out.print("\t"+student.getAge()+"\t");
            System.out.println("\t"+student.getScore()+"\t");
        }
    }//:遍历打印学生信息

    public Double getMaxScore(Student[] arr) {
        return getMaxStudent(arr).getScore();
    }

    //:获取学生成绩的最高分
    public Student getMaxStudent(Student[] arr) {
        Double max=arr[0].getScore();
        int index=0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i].getScore()>max){
                index=i;
            }
        }
        return arr[index];
    }

    //:获取成绩最高的学员
    public Double getAverageScore(Student[] arr) {
        Double sum=0.0;
        for (Student student : arr) {
            sum += student.getScore();
        }
        return sum/arr.length;

    }//:获取学生成绩的平均值

    public int getCount(Student[] arr) {
        int count=0;
        for (Student student : arr) {
            if (student.getScore() < 60) {
                count++;
            }
        }
        return count;
    }//:获取不及格的学员数量

}
